import 'core-js/stable';
import 'regenerator-runtime/runtime';

import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';

/**
 * Swiper
 */
import { Swiper } from 'swiper/swiper-bundle.esm';
import 'swiper/swiper-bundle.css';

/**
 * 图片预览
 */
import preview from 'vue-photo-preview';
import 'vue-photo-preview/dist/skin.css';
Vue.use(preview);

/**
 * 复制
 */
import VueClipboard from 'vue-clipboard2';
Vue.use(VueClipboard);

/**
 * echarts
 */
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;

Vue.prototype.$swiper = Swiper;
Vue.prototype.$swiperOption = {
  autoplay: false,
  pagination: {
    el: '.swiper-pagination',
    clickable: true,
  },
  navigation: {
    nextEl: '.swiper-next',
    prevEl: '.swiper-prev',
  },
  slidesPerView: 'auto',
  observer: true,
  observeParents: true,
};

/**
 * ElementUI 引用
 */
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI, {
  size: 'mini',
});

// 引入组件和样式
import RouterTab from 'vue-router-tab';
import 'vue-router-tab/dist/lib/vue-router-tab.css';
Vue.use(RouterTab);

/**
 * Service逻辑引用
 */
import axios from './utils/axios';
import API from './config/API';

// ========================== Service
import ZeesuuService from '@zeesuu/service';
Vue.use(ZeesuuService, {
  $http: axios,
  apis: API,
  debug: process.env.NODE_ENV === 'development',
});

// ========================== 枚举
import ENUMS from './config/ENUMS.js';
Vue.prototype.$ENUMS = ENUMS;

Vue.filter('price', function(value) {
  if (value === null || value === undefined) {
    return '';
  }
  return `${String((Number(value) / 100).toFixed(2))} 元`;
});

// ========================== 登录逻辑引用
import ZeesuuLogin from '@zeesuu/login';
Vue.use(ZeesuuLogin, { store });

// ========================== 搜索表格
import ZeesuSearchList from '@zeesuu/searchlist';
Vue.use(ZeesuSearchList);

// ========================== 动态下拉框设置
import ZeesuuSelect from '@zeesuu/select';
import CustomSelectData from 'config/CustomSelectData';

Vue.use(ZeesuuSelect, {
  api: {
    categorySl: { url: '/dict/categories' },
    levelSl: { url: '/dict/hardlevels' },
    jumpSl: { url: '/dict/jumpkinds' },
  },
  custom: CustomSelectData,
});

// ========================== 拖动
import draggable from 'vuedraggable';
Vue.component('draggable', draggable);

// ========================== 权限
import Permission from 'comp/Permission';
Vue.use(Permission);

// ========================== 上传
import UploadCore from 'utils/UploadCore';
Vue.use(UploadCore, {
  method: {
    public: Vue.prototype.$service.StsPublic,
    internal: Vue.prototype.$service.StsInternal,
  },
});

// ========================== 大图查看
import 'viewerjs/dist/viewer.css';
import Viewer from 'v-viewer';
Vue.use(Viewer, {
  // 解决element和v-viewer冲突
  defaultOptions: {
    zIndex: 9999,
  },
});

// ========================== 常量
import Const from 'mixins/Const';
Vue.mixin(Const);

// ========================== 样式
import 'assets/style/global';

Vue.prototype.$EventBus = new Vue();
Vue.config.productionTip = false;
Vue.prototype.window = window;

Vue.prototype.$cancel = function() {
  // 获取缓存的 请求取消标识 数组，取消所有关联的请求
  Vue.prototype._cancels_.forEach((cancel) => {
    cancel();
  });
};

// 时间格式
import dayjs from 'dayjs';
Vue.prototype.dayjs = dayjs;

// 注册走接口筛选的组件
import SearchSeclect from '@/components/SearchSeclect';
Vue.component('SearchSeclect', SearchSeclect);

window.JSON_HEADER = {
  headers: {
    'Content-Type': 'application/json',
  },
};

new Vue({
  router,
  store,

  render: (h) => h(App),
}).$mount('#app');
